package com.itlong.cloud.sdk.resource;

import com.itlong.cloud.POJO.DTO.sdk.CloudTalkSDKMediaSaveOrUpdateDTO;
import com.itlong.cloud.equip.sdk.ICloudTalkSDKMediaServiceClient;
import com.itlong.cloud.sdk.service.ICloudTalkSDKMediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <desc>
 *      云对讲SDK多媒体资源服务接口暴露实现类
 * <desc/>
 *
 * @createDate 2018/05/22
 */
@RestController
public class CloudTalkSDKMediaServiceResource implements ICloudTalkSDKMediaServiceClient {

    @Autowired
    private ICloudTalkSDKMediaService iCloudTalkSDKMediaService;

    /**
     * <desc>
     *      根据条件projectId和deviceUnique获取云对讲设备类型
     * </desc>
     *
     * @param projectId    项目id
     * @param deviceUnique 设备序列号
     * @return 云对讲类型
     * @author wangzhi
     * @createDate 2018/05/22
     */
    @Override
    @PostMapping(path = "cloudTalkSDK/media/getCloudIntercomByProjectIdAndDeviceUnique")
    public Integer getCloudIntercomByProjectIdAndDeviceUnique(@RequestParam("projectId") String projectId,
                                                              @RequestParam("deviceUnique") String deviceUnique) throws Exception {
        return iCloudTalkSDKMediaService.getCloudIntercomByProjectIdAndDeviceUnique(projectId,deviceUnique);
    }

    /**
     * <desc>
     *      根据条件projectId和mediaId查询多媒体资源mediaId，用于验证多媒体资源是否存在
     * </desc>
     *
     * @param projectId 项目id
     * @param mediaId   多媒体资源id
     * @return 多媒体资源id
     * @author wangzhi
     * @createDate 2018/05/22
     */
    @Override
    @PostMapping(path = "cloudTalkSDK/media/getMediaIdByProjectIdAndMediaId")
    public String getMediaIdByProjectIdAndMediaId(@RequestParam("projectId") String projectId, @RequestParam("mediaId") String mediaId) throws Exception {
        return iCloudTalkSDKMediaService.getMediaIdByProjectIdAndMediaId(projectId,mediaId);
    }

    /**
     * <desc>
     *      保存多媒体资源
     * </desc>
     *
     * @param cloudTalkSDKMediaSaveDTOS 待保存的数据集
     * @return
     * @author wangzhi
     * @createDate 2018/05/22
     */
    @Override
    @PostMapping(path = "cloudTalkSDK/media/saveMedia")
    public List<CloudTalkSDKMediaSaveOrUpdateDTO> saveMedia(@RequestBody List<CloudTalkSDKMediaSaveOrUpdateDTO> cloudTalkSDKMediaSaveDTOS) throws Exception {
        return iCloudTalkSDKMediaService.saveMedia(cloudTalkSDKMediaSaveDTOS);
    }

    /**
     * <desc>
     *      更新多媒体资源
     * </desc>
     *
     * @param cloudTalkSDKMediaUpdateDTOS 待更新的数据集
     * @return
     * @author wangzhi
     * @createDate 2018/05/22
     */
    @Override
    @PostMapping(path = "cloudTalkSDK/media/updateMedia")
    public List<CloudTalkSDKMediaSaveOrUpdateDTO> updateMedia(@RequestBody List<CloudTalkSDKMediaSaveOrUpdateDTO> cloudTalkSDKMediaUpdateDTOS) throws Exception {
        return iCloudTalkSDKMediaService.updateMedia(cloudTalkSDKMediaUpdateDTOS);
    }
}
